<?php

/**
 * Ignus Framework
 *
 * @author Sergey Palyanov <sergey.palyanov@gmail.com>
 * @link http://code.google.com/p/ignus-php/
 * @license http://apache.org/licenses/LICENSE-2.0
 * @package Ignus
 * @subpackage Util
 * @since 0.1
 */

namespace Ignus\Util;

/**
 * @package Ignus
 * @subpackage Util
 * @since 0.5.2
 */
abstract class StringUtils
{
    /**
     * Chop off string to size {@param $size}
     * @static
     * @param string  $string String to chop off
     * @param integer $size   Size of chopped string
     * @param string  $end    Suffix to append
     * @return string
     */
    public static function chop($string, $size, $end = '...')
    {
        if ($size >= strlen($string))
            return $string;

        $blank = strpos($string, ' ', $size);
        if ($blank === false)
            return $string;

        return rtrim(substr($string, 0, $blank)) . $end;
    }
}
